<?php 
	include('function/connection.php');
	$sup_id = $sup_name = $sup_address = $sup_contact1 = $sup_contact2 = "";
	$action ="insert";
	$btn = "Save";
	
	// Select customer info
	if(isset($_GET['id'])){
		$querySelectCustomer = "SELECT * FROM tbl_suppliers WHERE id= $_GET[id]";
		$result = mysql_query($querySelectCustomer);
		$rowCustomer = mysql_fetch_array($result);
			$sup_id = $rowCustomer['sup_id'];
			$sup_name = $rowCustomer['sup_name'];
			$sup_address = $rowCustomer['sup_address'];
			$sup_contact1 = $rowCustomer['sup_contact1'];
			$sup_contact2 = $rowCustomer['sup_contact2'];
			
			$action = "update&id=".$_GET['id'];		
			$btn = "Update";
			
	}
	if(!isset($_GET['id'])){
		// max id
		$sql="SELECT id FROM tbl_suppliers ORDER BY id DESC";
		$result=query($sql);
		$row=fetch_array($result);
		$id=$row["id"] +1;
		$sup_id="S".$id;
	}
?>

<form action="verify_supplier.php?action=<?php echo $action ?>" method="post" enctype="multipart/form-data" class="form" name="form1" id="form1">
	<table  width="770">
        <thead>
            <tr>
                <th>Please insert your customer information:<br /><span class="red">* require feild</span></th>
            </tr>
        </thead>
        <tr>
    	<?php 
			if(@$errors!=""){
				echo " <td ><span class='red'>". @$errors."</span></td>";
			}else{
				if(isset($_REQUEST['msgStatus']))
					echo " <td ><span class='red'>". $_REQUEST['msgStatus']."</span></td>";
			 }
			?>
   		 </tr>
	</table>
    <table class="bordered" width="770">
		<tr>
			<td colspan="2">
            	<label><span class="red">*</span> Supplier ID:</label>
				<input type="text" class="txtID" name="txtCusID" value="<?php echo $sup_id;?>" /> </td>           
            <td colspan="2">
            	<label><span class="red">*</span> Supplier Name:</label>
            	<input type="text"  name="txtCusName" value="<?php echo $sup_name ?>" class="input req-min" minlength="1" style="width:200px; height:30px;" /> 
            </td>
		</tr>
        <tr>
        	<td colspan="4">
            	<label>Address:</label>
				<input type="text" class="txtCusAddress" name="txtCusAddress" value="<?php echo $sup_address ?>" />
           	</td>
		</tr>
        <tr>
			<td colspan="2">
            	<label>Contact1:</label>
				<input type="text" class="input req-min" minlength="1" style="width:200px; height:30px;" name="txtCusContact1" value="<?php echo $sup_contact1 ?>" />
            </td>
            <td colspan="2">
            	<label>Contact2:</label>
            	<input type="text" class="txtCusContact2" name="txtCusContact2" value="<?php echo $sup_contact2 ?>" />
            </td>
		</tr>
		<tr>
			<td colspan="4"><input type="submit" class="btnSubmit" name="Submit" id="Submit" value="<?php echo $btn ?>" />&nbsp; 
            <input type="button" class="btnSubmit" name="btnSubmit" value="Cancel" onclick="redirect('index.php?page=supplier_list&action=supplier_list')" /></td>
		</tr>
	</table>
</form>